package com.opensource.component.dinging.message;

import com.opensource.component.dinging.message.enums.MessageType;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

import org.springframework.util.StringUtils;

/**
 * created by zhanglong and since  2019/12/27  10:03 下午
 *
 * @description: 描述
 */
public class TextMessage extends BaseDingMessage {

    /**
     * 文本消息的具体内容
     */
    private final String content;

    private final AtPhone atPhone;

    public TextMessage(String content) {
        this.content = content;
        this.atPhone = new AtPhone();
    }

    public TextMessage(String content, AtPhone atPhone) {
        if (StringUtils.isEmpty(content)) {
            throw new IllegalArgumentException("please check the necessary parameters!");
        }
        this.content = content;
        this.atPhone = atPhone == null ? new AtPhone() : atPhone;
    }

    @Override
    public Map<String, Object> toMessageMap() {

        HashMap<String, Object> resultMap = new HashMap<>(8);
        resultMap.put("msgtype", MessageType.TEXT.value());

        HashMap<String, String> textItems = new HashMap<>(8);
        textItems.put("content", this.content);
        resultMap.put("text", textItems);

        HashMap<String, Object> atItems = new HashMap<>(8);
        atItems.put("atMobiles", this.atPhone.getAtMobiles());
        atItems.put("isAtAll", this.atPhone.isAtAll());
        resultMap.put("at", atItems);

        return resultMap;
    }

}
